package com.ityang.hhhh.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ityang.hhhh.conm.R;
import com.ityang.hhhh.domain.Shopping;
import com.ityang.hhhh.domain.Shopping_fl;
import com.ityang.hhhh.service.IShoppingService;
import com.ityang.hhhh.service.IShopping_flService;
import com.ityang.hhhh.utils.XinWen;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 *
 *商品
 * @author ityang
 * @since 2022-05-17
 */
@RestController
@RequestMapping("/shopping")
public class ShoppingController {
    @Autowired
    private IShoppingService shoppingService;
    @Autowired
    private IShopping_flService shopping_flService;

    /**
     * 查询商品
     * @return
     */
    @GetMapping("/mall")
    public R mall(){

        List<Shopping> shoppingList = shoppingService.list();

        return R.success(shoppingList);
    }

    /**
     * 商品插入
     * @param shopping
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody Shopping shopping){
        shoppingService.save(shopping);
        return R.success("插入成功");
    }

    /**
     * 查询商品规格
     * @param id
     * @return
     */
    @PostMapping("/fal")
    public R<List<Shopping_fl>> fal(Long id){
        LambdaQueryWrapper<Shopping_fl> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Shopping_fl::getShoppingId,id);
        List<Shopping_fl> flList = shopping_flService.list(lqw);
        return R.success(flList);
    }

    /**
     * 调用新闻api
     * @return
     */
    @GetMapping("/xin")
    public R xinwen(){
        String can = "";
        //String request = XinWen.request(XinWen.httpUrl, can);
        //return R.success(request);
        return null;
    }




}

